package com.ganmiao.web.portal.controller.sys;

import com.ganmiao.resp.CommonResultRes;
import com.ganmiao.resp.MobBaseRes;
import com.ganmiao.resp.PageResult;
import com.ganmiao.server.supplier.dto.InformationDto;
import com.ganmiao.server.supplier.dto.UpdatePasswordDto;
import com.ganmiao.server.supplier.vo.InformationVo;
import com.ganmiao.server.sys.dto.SysUserDto;
import com.ganmiao.server.sys.query.SysUserQuery;
import com.ganmiao.server.sys.service.SysUserService;
import com.ganmiao.server.sys.vo.SysUserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 用户信息
 */
@Api(tags = "用户信息")
@Slf4j
@RestController
@RequestMapping("/sysUser")
public class SysUserController {

    //用户信息
    @Autowired
    private SysUserService sysUserService;

    /**
     * 新增
     *
     * @param sysUserDto
     * @return
     */
    @ApiOperation("新增")
    @PostMapping("/addSysUser")
    public MobBaseRes addSysUser(@RequestBody SysUserDto sysUserDto) {
        return sysUserService.addSysUser(sysUserDto);
    }

    /**
     * 删除
     *
     * @param userId
     * @return
     */
    @ApiOperation("删除")
    @PutMapping("/deleteSysUser/{userId}")
    public MobBaseRes deleteSysUser(@PathVariable Integer userId) {
        return sysUserService.deleteSysUser(userId);
    }

    /**
     * 修改
     *
     * @param sysUserDto
     * @return
     */
    @ApiOperation("修改")
    @PutMapping("/updateSysUser")
    public MobBaseRes updateSysUser(@RequestBody SysUserDto sysUserDto) {
        return sysUserService.updateSysUser(sysUserDto);
    }

    /**
     * 分页列表
     *
     * @param sysUserQuery
     * @return
     */
    @ApiOperation("分页列表")
    @GetMapping("/getSysUserList")
    public CommonResultRes<PageResult<SysUserVo>> getSysUserList(SysUserQuery sysUserQuery) {
        return new CommonResultRes<>(sysUserService.getSysUserList(sysUserQuery));
    }

    /**
     * 获取用户信息(详情)
     *
     * @param userId
     * @return
     */
    @ApiOperation("获取用户信息(详情)")
    @GetMapping("/getSysUserById/{userId}")
    public CommonResultRes<SysUserVo> getSysUserById(@PathVariable Integer userId) {
        return new CommonResultRes<>(sysUserService.getSysUserById(userId));
    }

    /**
     * 查询个人信息
     *
     * @return
     */
    @ApiOperation("查询个人信息")
    @GetMapping("/getInformation")
    public CommonResultRes<InformationVo> getInformation() {
        return sysUserService.getInformation();
    }

    /**
     * 个人信息>确认
     *
     * @return
     */
    @ApiOperation("个人信息>修改个人信息")
    @PostMapping("/updateInformation")
    public MobBaseRes updateInformation(@RequestBody InformationDto informationDto) {
        return sysUserService.updateInformation(informationDto);
    }

    /**
     * 修改密码
     *
     * @return
     */
    @ApiOperation("个人信息>修改密码")
    @PostMapping("/updatePassword")
    public MobBaseRes updatePassword(@RequestBody UpdatePasswordDto updatePasswordDto) {
        return sysUserService.updatePassword(updatePasswordDto);
    }
}
